import { useEffect } from "react"
import { useOutletContext } from "react-router-dom"
import type { navBar } from "../layouts/MainLayout"

//修改头部导航栏信息
type UseOptions = Partial<navBar>
// 明确接收的 props 类型
interface navContext {
    setNav: (config: Partial<navBar>) => void,
    isLayoutInit: boolean
}

export const useNav = (options?: UseOptions) => {
    const { setNav, isLayoutInit } = useOutletContext<navContext>()

    // console.log(isLayoutInit,options,setNav)
    
    useEffect(() => {
        if (options && setNav && isLayoutInit) {
            setNav(options)
            // console.log('useNav')
        }

    }, [isLayoutInit,setNav,options])
}